package leets.leet2264;

public class Solution {
    public String largestGoodInteger(String num) {
        if(num.length()==0){
            return "";
        }
        char c=num.charAt(0);
        int n=1;
        char res='a';
        for (char cs:num.substring(1).toCharArray()){
            if(res=='a'||cs>res){

                if(c!=cs){
                    n=0;
                }
                c=cs;
                n++;
                if(n==3){
                    res=c;
                }
            }else {
                n=0;
            }
        }
        if(res!='a'){
            return (res+"").repeat(3);
        }else {
            return "";
        }
    }
}